import { Component, Injector ,OnInit } from '@angular/core';

import { AppComponentBase } from '@shared/app-component-base';

import { WaterQualityColorServiceProxy,WaterQualityColorDto } from '@shared/service-proxies/service-proxies';

import { CreateColorModalComponent } from './create-color-modal.component';

@Component({
  selector: 'app-colors',
  templateUrl: './colors.component.html',
  styles: []
})
export class ColorsComponent extends AppComponentBase  implements OnInit {

  constructor(injector: Injector,
          private _service:WaterQualityColorServiceProxy ) { 
    super(injector);
  }

  list=[];

  ngOnInit() {
    this.load();
  }

  load(){
    this.loading=true;
    this._service.getAllWaterQualitys()
      .finally(()=>{
        this.loading=false;
      })
      .subscribe((res)=>{
        this.list = res;
      });
  }

  create(id: string): void {
    
    this.showModal(CreateColorModalComponent,{
        id : id
    }, () => {
        this.load();
    });
  }

  delete(data: WaterQualityColorDto): void {
    this.message.confirm(
        '确认删除该信息?',
        isConfirmed => {
            if (isConfirmed) {
                this._service.deleteWaterQualityColor(data.id).subscribe(() => {
                    this.load();
                        this.notify.success(this.l('SuccessfullyDeleted'));
                });
            }
        }
    );
}

}
